const App = {
    mixins: [Save],//配置文件，路径/utils/mixins.js
    data() {
        return {
            mcategory: [],
            qualification: [],
            childDataForm: [{
                Children: {
                    merchant_qualification: [],
                    merchant_business_mapping_blue_plate: [],
                }
            }],
            dataForm: {
                County_Nubmer: '232723',
            },
            mcategory1: [],
            personal_information: [],
            mapping_blue_plate: [],
            childDataForm1: [{}],
            room_type: [],
            image_type: [],
            image_category: [],
            window_type: [],
            room_facility_type: [],
            merchant_alias_type: [],
            blue_plate: [],
            tabs_action: {},
            select_blue_plate: {},
            showComponent: true,
            showblueplate: true,
            drag: false,
            city: [],
            city1: [],
            merchant_business_mapping_blue_plate: [],//修改时留存用
        };
    },
    computed: {
        mcategory2() {
            return function (obj) {
                let arr = this.mcategory1.filter(i => !this.childDataForm.filter(x => x.Row_Status != '1').some(x => x.Merchant_Category_SerialNumber == i.Merchant_Category_SerialNumber) || i.Merchant_Category_SerialNumber == obj.Merchant_Category_SerialNumber);
                arr.forEach(item => {
                    if (item.children && item.children.length > 0) {
                        item.children.forEach(ite => {
                            if (this.childDataForm.filter(x => x.Row_Status != '1').some(x => x.Merchant_Category_SerialNumber == ite.Merchant_Category_SerialNumber && ite.Merchant_Category_SerialNumber != obj.Merchant_Category_SerialNumber)) {
                                ite.disabled = true;
                            }
                        })
                    }
                })
                return arr;
            }
        }
    },
    mounted() {
        this.getCategory();
        if (this.action == 'Add') {
            this.changeCity('232723')
        }
        // this.$nextTick(() => { //拖拽排序
        //     var $ul = document.querySelector('#childDataForm1');
        //     $ul.addEventListener('selectstart', function (e) {
        //         e.preventDefault();
        //     })
        //     this.Sortable = Sortable.create($ul, {
        //         handle: '.el-descriptions',
        //         draggable: '.el-descriptions',
        //         animation: 150,
        //         onUpdate: (event) => {
        //             let newIndex = event.newIndex, oldIndex = event.oldIndex;
        //             $li = $ul.children[newIndex], $oldLi = $ul.children[oldIndex]
        //             //先删除移动的节点, 再插入移动的节点到原有节点，还原了移动的操作
        //             $ul.removeChild($li)
        //             if (newIndex > oldIndex) {
        //                 $ul.insertBefore($li, $oldLi)
        //             } else {
        //                 $ul.insertBefore($li, $oldLi.nextSibling)
        //             }
        //             //通过改变vue遍历数组移动节点
        //             let item = this.childDataForm1[oldIndex];
        //             this.childDataForm1.splice(oldIndex, 1);
        //             this.childDataForm1.splice(newIndex, 0, item);
        //         }
        //     })
        //     this.Sortable.option('disabled', !this.drag);
        // })
    },
    methods: {
        success(file) {
            const that = this;
            const formData = new FormData();
            formData.append('file', file, file.name);
            let oFileReader = new FileReader();
            oFileReader.readAsDataURL(file);
            oFileReader.onload = async function (e) {
                $.ajax({
                    headers: requestHeaders("JSON"),
                    url: `${mh}/clientOperation/OCR_BusinessLicense`,
                    type: "post",
                    data: e.target.result.replace('data:image/jpeg;', ''),
                    success: (res) => {
                        if (res.words_result) {
                            that.dataForm.Merchant_Name = res.words_result['单位名称'].words;
                            that.dataForm.Legal_Person = res.words_result['法人'].words;
                            that.dataForm.Business_License = res.words_result['社会信用代码'].words;
                            that.dataForm.Merchant_Address = res.words_result['地址'].words;
                            that.dataForm.Merchant_Description = res.words_result['经营范围'].words;
                            that.dataForm.Register_Date = res.words_result['核准日期'].words;

                            that.inputMerchant_Address(that.dataForm.Merchant_Address);
                        }
                    },
                    complete: (XMLHttpRequest) => {
                        requestPretreatment(XMLHttpRequest);
                    },
                    dataType: "json",
                });
            }
        },
        changeCity(val) {
            if (val) {
                this.dataForm.Province_Number = val.substring(0, 2) + "0000";
                this.dataForm.City_Number = val.substring(0, 4) + "00";
                $.ajax({
                    headers: requestHeaders(),
                    url: `${mh}/clientOperation/getDistrictTree`,
                    type: "GET",
                    data: {
                        DistrictCode: val
                    },
                    success: (data) => {
                        this.city1 = data[0].children;
                    },
                    complete: (XMLHttpRequest) => {
                        requestPretreatment(XMLHttpRequest);
                    },
                    dataType: "json",
                });
            } else {
                this.dataForm.Province_Number = '';
                this.dataForm.City_Number = '';
                this.dataForm.County_Nubmer = '';
                this.dataForm.Town_Number = '';
                this.dataForm.Village_Number = '';
            }
        },
        changeCity1(val) {
            if (val) {
                this.dataForm.Town_Number = val.substring(0, 9);
            } else {
                this.dataForm.Town_Number = '';
                this.dataForm.Village_Number = '';
            }
        },
        handledrag() {
            this.drag = !this.drag;
            this.Sortable.option('disabled', !this.drag);
        },
        inputMerchant_Address(val) {
            if (val) {
                $.ajax({
                    url: `${y}/getMapWorldAddressResolutionAction`,
                    type: "get",
                    data: {
                        Address: val
                    },
                    success: (res) => {
                        if (res.Status == 'success') {
                            const bd09Lng = res.Data.lon;
                            const bd09Lat = res.Data.lat;

                            // 转换为WGS-84坐标
                            const wgs84 = bd09ToWGS84(bd09Lng, bd09Lat);
                            // 腾讯2000
                            const gcj02 = bd09ToGCJ02(bd09Lng, bd09Lat);
                            this.dataForm.Merchant_Coords = "[" + wgs84.lng + "," + wgs84.lat + "]";
                            // this.dataForm.Merchant_Coords  = "["+ res.Data.lon +","+res.Data.lat  + "]";
                        }
                    },
                    complete: (XMLHttpRequest) => {

                    },
                    dataType: "json",
                });
            }

        },
        changeBluePlate(Merchant_Category_SerialNumber, item) {//选择类别时
            let Blue_Plate_SerialNumber = this.dataForm.Blue_Plate_SerialNumber;
            //判断当前是否选择类别
            if (Merchant_Category_SerialNumber) {
                this.select_blue_plate[Merchant_Category_SerialNumber] = {
                    Merchant_Alias: '',
                    Merchant_Scale: '',
                    Contact_Phone: '',
                    Open_Hours: '',
                    Close_Hours: '',
                    Merchant_Main: '',
                    Picture_URL: '',
                    Blue_Plate_SerialNumber,
                    Merchant_Alias_Type_SerialNumber: [],
                    Children: {
                        merchant_alias_image: [{}]
                    }
                }

                //tab 头 
                // let obj = this.room_type.filter(i => i.Merchant_Category_SerialNumber == Merchant_Category_SerialNumber)[0]
                // if (!obj) {
                //     this['room_type'].push({
                //         Merchant_SerialNumber: item.Merchant_SerialNumber,
                //         Merchant_Category_SerialNumber,
                //         Blue_Plate_SerialNumber,
                //         Row_Status: '0',
                //     })
                // } else {
                //     obj.Merchant_Category_SerialNumber = Merchant_Category_SerialNumber;
                //     obj.Blue_Plate_SerialNumber = Blue_Plate_SerialNumber;
                // }
                for (let key in this.select_blue_plate) {
                    if (!this.childDataForm.some(x => x.Merchant_Category_SerialNumber == key)) {
                        delete this.select_blue_plate[key];
                    }
                }
            }


            // if (this.action == 'Add') {
            //     this.room_type = this.room_type.filter(i => this.childDataForm.some(x => x.Merchant_Category_SerialNumber == i.Merchant_Category_SerialNumber));
            // } else if (this.action == 'Modify') {
            //     console.log(this.room_type);
            // }

            // this.room_type = this.room_type.filter(i => this.childDataForm.some(x => x.Merchant_Category_SerialNumber == i.Merchant_Category_SerialNumber));

            // if (this.action == 'Modify') {

            //     this.room_type = this.room_type.filter(i => this.childDataForm.some(x => x.Merchant_Category_SerialNumber == i.Merchant_Category_SerialNumber));

            // }

        },
        changeBluePlate2(val) {
            for (let key in this.select_blue_plate) {
                const obj = this.select_blue_plate[key];
                obj.Blue_Plate_SerialNumber = val;
            };
        },
        getCategory() {
            $.ajax({
                url: `${absolutepath()}api/Districtjl.json`,
                method: "get",
                success: (data) => {
                    data.forEach(item => {
                        item.children.forEach(ite => {
                            ite.children.forEach(it => {
                                it.children = undefined
                            })
                        })
                    })
                    this.city = data;
                }
            });
            $.ajax({
                headers: requestHeaders(),
                url: `${mh}/generalBusiness/generalQueryByTableName`,
                type: "POST",
                data: {
                    Data: 'merchant_category',
                    Condition: "Row_Status='0'",
                },
                success: (data) => {
                    this.mcategory = data; // 直接使用 this
                },
                complete: (XMLHttpRequest) => {
                    requestPretreatment(XMLHttpRequest);
                },
                dataType: "json",
            });
            $.ajax({
                headers: requestHeaders(),
                url: `${mh}/generalBusiness/generalQueryByTableName`,
                type: "POST",
                data: {
                    Data: 'merchant_alias_type',
                    Condition: "Row_Status='0'",
                },
                success: (data) => {
                    this.merchant_alias_type = data; // 直接使用 this
                },
                complete: (XMLHttpRequest) => {
                    requestPretreatment(XMLHttpRequest);
                },
                dataType: "json",
            });

            $.ajax({
                headers: requestHeaders(),
                url: `${mh}/generalBusiness/generalQueryForObtainingTrees`,
                type: "GET",
                data: {
                    TableName: 'merchant_category',
                    NodeCode: "",
                },
                success: (data) => {
                    this.mcategory1 = data; // 直接使用 this
                },
                complete: (XMLHttpRequest) => {
                    requestPretreatment(XMLHttpRequest);
                },
                dataType: "json",
            });
            $.ajax({
                headers: requestHeaders(),
                url: `${mh}/generalBusiness/generalQueryByTableName`,
                type: "POST",
                data: {
                    Data: 'image_type',
                    Condition: "Row_Status='0'",
                },
                success: (data) => {
                    this.image_type = data; // 直接使用 this
                },
                complete: (XMLHttpRequest) => {
                    requestPretreatment(XMLHttpRequest);
                },
                dataType: "json",
            });
            $.ajax({
                headers: requestHeaders(),
                url: `${mh}/generalBusiness/generalQueryByTableName`,
                type: "POST",
                data: {
                    Data: 'image_category',
                    Condition: "Row_Status='0'",
                },
                success: (data) => {
                    this.image_category = data; // 直接使用 this
                },
                complete: (XMLHttpRequest) => {
                    requestPretreatment(XMLHttpRequest);
                },
                dataType: "json",
            });
            $.ajax({
                headers: requestHeaders(),
                url: `${mh}/generalBusiness/generalQueryForObtainingTrees`,
                type: "GET",
                data: {
                    TableName: 'room_facility_type',
                    NodeCode: "",
                },
                success: (data) => {
                    this.room_facility_type = data; // 直接使用 this
                },
                complete: (XMLHttpRequest) => {
                    requestPretreatment(XMLHttpRequest);
                },
                dataType: "json",
            });
            $.ajax({
                headers: requestHeaders(),
                url: `${mh}/generalBusiness/generalQueryByTableName`,
                type: "POST",
                data: {
                    Data: 'window_type',
                    Condition: "Row_Status='0'",
                },
                success: (data) => {
                    this.window_type = data; // 直接使用 this
                },
                complete: (XMLHttpRequest) => {
                    requestPretreatment(XMLHttpRequest);
                },
                dataType: "json",
            });
            $.ajax({
                headers: requestHeaders(),
                url: `${mh}/generalBusiness/generalQueryByTableName`,
                type: "POST",
                data: {
                    Data: 'personal_information',
                    Condition: "Row_Status='0'",
                },
                success: (data) => {
                    this.personal_information = data; // 直接使用 this
                },
                complete: (XMLHttpRequest) => {

                    requestPretreatment(XMLHttpRequest);
                },
                dataType: "json",
            });
            $.ajax({
                headers: requestHeaders(),
                url: `${mh}/generalBusiness/generalQueryByTableName`,
                type: "POST",
                data: {
                    Data: 'blue_plate_information',
                    Condition: "Row_Status='0'",
                },
                success: (data) => {
                    this.blue_plate = data; // 直接使用 this
                },
                complete: (XMLHttpRequest) => {
                    requestPretreatment(XMLHttpRequest);
                },
                dataType: "json",
            });
            $.ajax({
                headers: requestHeaders(),
                url: `${mh}/generalBusiness/generalQueryByTableName`,
                type: "POST",
                data: {
                    Data: 'merchant_qualification_type',
                    Condition: "Row_Status='0'",
                },
                success: (data) => {
                    this.qualification = data; // 直接使用 this
                },
                complete: (XMLHttpRequest) => {
                    requestPretreatment(XMLHttpRequest);
                },
                dataType: "json",
            });
        },
        handleAdd(formName) {
            if (this.action === 'Add') {
                if (formName == 'childDataForm') {
                    this[formName].push({
                        Children: {
                            merchant_qualification: [],
                            merchant_business_mapping_blue_plate: [],
                        }
                    })
                } else {
                    this[formName].push({})
                }
            } else if (this.action === 'Modify') {
                let lJSONObject_Data_Options = new Object();
                lJSONObject_Data_Options = JSON.parse(document.getElementById("MainTable").getAttribute("data-options"));
                let ls_primary_key = lJSONObject_Data_Options.primary_key;
                let lJSONObject_Data = new Object();
                lJSONObject_Data[ls_primary_key] = this.nodeKey;
                if (formName == 'childDataForm') {
                    lJSONObject_Data['Children'] = { merchant_qualification: [], merchant_business_mapping_blue_plate: [] }
                }
                this[formName].push(lJSONObject_Data);
            }
        },
        handleRemove(formName, min = 1) {
            if (this.action === 'Add') {
                if (this[formName].length > min) {
                    this[formName].pop();
                    if (formName === 'childDataForm') {
                        // this.room_type = this.room_type.filter(i => this.childDataForm.some(x => x.Merchant_Category_SerialNumber == i.Merchant_Category_SerialNumber))
                        for (let key in this.select_blue_plate) {
                            if (!this.childDataForm.some(x => x.Merchant_Category_SerialNumber == key)) {
                                delete this.select_blue_plate[key];
                            }
                        }
                    }
                } else {
                    this.$message({
                        message: '不能在删除了',
                        type: 'warning'
                    })
                }
            } else if (this.action === 'Modify') {
                if (this[formName].filter(item => item.Row_Status != '1').length > min) {
                    let i = this[formName].filter(item => item.Row_Status != '1').length - 1
                    let obj = this[formName].filter(item => item.Row_Status != '1')[i]
                    if (!Object.keys(obj).some(item => item.includes('_Original'))) {
                        this[formName].pop();
                        if (formName === 'childDataForm') {
                            // this.room_type = this.room_type.filter(i => this.childDataForm.some(x => x.Merchant_Category_SerialNumber == i.Merchant_Category_SerialNumber))
                            for (let key in this.select_blue_plate) {
                                if (!this.childDataForm.filter(i => i.Row_Status != '1').some(x => x.Merchant_Category_SerialNumber == key)) {
                                    delete this.select_blue_plate[key];
                                }
                            }
                        }
                    } else {
                        this.$confirm('该操作将删除此条数据,是否继续?', '提示', {
                            confirmButtonText: '确定',
                            cancelButtonText: '取消',
                            type: 'warning',
                        }).then(() => {
                            this[formName].filter(item => item.Row_Status != '1')[i].Row_Status = '1';
                            if (formName === 'childDataForm') {
                                // this.room_type = this.room_type.filter(i => this.childDataForm.some(x => x.Merchant_Category_SerialNumber == i.Merchant_Category_SerialNumber))
                                for (let key in this.select_blue_plate) {
                                    if (!this.childDataForm.filter(i => i.Row_Status != '1').some(x => x.Merchant_Category_SerialNumber == key)) {
                                        delete this.select_blue_plate[key];
                                    }
                                }
                            }
                        }).catch(() => {
                            this.$message({
                                type: 'warning',
                                message: '已取消删除'
                            });
                        });
                    }
                } else {
                    this.$message({
                        message: '不能在删除了',
                        type: 'warning'
                    })
                }
            }

        },
        //孙表
        handleAdd1(row) {
            if (this.action === 'Add') {
                row.Children.merchant_qualification.push({
                    Merchant_Business_Scope_SerialNumber: '',
                    Row_Status: '0',
                });
            } else if (this.action === 'Modify') {
                row.Children.merchant_qualification.push({
                    Merchant_Business_Scope_SerialNumber: row.Merchant_Business_Scope_SerialNumber,
                    Row_Status: '0',
                });
            }
        },
        handleRemove1(row) {
            if (this.action === 'Add') {
                if (row.Children.merchant_qualification.length > 0) {
                    row.Children.merchant_qualification.pop();
                } else {
                    this.$message({
                        message: '不能在删除了',
                        type: 'warning'
                    })
                }
            } else if (this.action === 'Modify') {
                if (row.Children.merchant_qualification.filter(item => item.Row_Status != '1').length > 1) {
                    let i = row.Children.merchant_qualification.filter(item => item.Row_Status != '1').length - 1
                    let obj = row.Children.merchant_qualification.filter(item => item.Row_Status != '1')[i]
                    if (!Object.keys(obj).some(item => item.includes('_Original'))) {
                        row.Children.merchant_qualification.pop();
                    } else {
                        this.$confirm('该操作将删除此条数据,是否继续?', '提示', {
                            confirmButtonText: '确定',
                            cancelButtonText: '取消',
                            type: 'warning',
                        }).then(() => {
                            row.Children.merchant_qualification.filter(item => item.Row_Status != '1')[i].Row_Status = '1'
                        }).catch(() => {
                            this.$message({
                                type: 'warning',
                                message: '已取消删除'
                            });
                        });
                    }
                } else {
                    this.$message({
                        message: '不能在删除了',
                        type: 'warning'
                    })
                }
            }
        },
        handleAdd2(obj) {
            if (this.action === 'Add') {
                obj.Children.merchant_alias_image.push({
                    Row_Status: '0',
                });
            } else if (this.action === 'Modify') {
                obj.Children.merchant_alias_image.push({
                    Merchant_Mapping_Blue_Plate_SerialNumber: obj.Merchant_Mapping_Blue_Plate_SerialNumber,
                    Row_Status: '0',
                });
            }
        },
        handleRemove2(row) {
            if (this.action === 'Add') {
                if (row.Children.merchant_alias_image.length > 0) {
                    row.Children.merchant_alias_image.pop();
                } else {
                    this.$message({
                        message: '不能在删除了',
                        type: 'warning'
                    })
                }
            } else if (this.action === 'Modify') {
                if (row.Children.merchant_alias_image.filter(item => item.Row_Status != '1').length > 1) {
                    let i = row.Children.merchant_alias_image.filter(item => item.Row_Status != '1').length - 1
                    let obj = row.Children.merchant_alias_image.filter(item => item.Row_Status != '1')[i]
                    if (!Object.keys(obj).some(item => item.includes('_Original'))) {
                        row.Children.merchant_alias_image.pop();
                    } else {
                        this.$confirm('该操作将删除此条数据,是否继续?', '提示', {
                            confirmButtonText: '确定',
                            cancelButtonText: '取消',
                            type: 'warning',
                        }).then(() => {
                            row.Children.merchant_alias_image.filter(item => item.Row_Status != '1')[i].Row_Status = '1'
                        }).catch(() => {
                            this.$message({
                                type: 'warning',
                                message: '已取消删除'
                            });
                        });
                    }
                } else {
                    this.$message({
                        message: '不能在删除了',
                        type: 'warning'
                    })
                }
            }
        },
        getData(nodeKey) {//查询
            const that = this;
            $.ajax({
                headers: requestHeaders(),
                url: `${mh}/generalBusiness/generalQueryByTableNameWithOriginal`,
                method: "post",
                data: {
                    Data: 'merchant',
                    Condition: `Merchant_SerialNumber='${nodeKey}'`,
                },
                success: (res) => {
                    this.dataForm = res[0];
                    this.changeCity(this.dataForm.County_Nubmer)
                },
                complete: (XMLHttpRequest) => {
                    requestPretreatment(XMLHttpRequest);
                },
            })
            $.ajax({
                headers: requestHeaders(),
                url: `${mh}/generalBusiness/generalQueryByTableNameWithOriginal`,
                method: "post",
                data: {
                    Data: 'merchant_image',
                    Condition: `Merchant_SerialNumber='${nodeKey}'`,
                },
                success: (res) => {
                    this.childDataForm1 = res;
                },
                complete: (XMLHttpRequest) => {
                    requestPretreatment(XMLHttpRequest);
                },
            })
            $.ajax({
                headers: requestHeaders(),
                url: `${mh}/generalBusiness/generalQueryByTableNameWithOriginal`,
                method: "post",
                data: {
                    Data: 'merchant_business_scope',
                    Condition: `Merchant_SerialNumber='${nodeKey}' AND Row_Status='0'`,
                },
                success: (res) => {
                    this.childDataForm = res;
                    res.forEach(item => {
                        item['Children'] = { merchant_qualification: [], merchant_business_mapping_blue_plate: [] };
                        $.ajax({
                            headers: requestHeaders(),
                            url: `${mh}/generalBusiness/generalQueryByTableNameWithOriginal`,
                            method: "post",
                            data: {
                                Data: 'merchant_qualification',
                                Condition: `Merchant_Business_Scope_SerialNumber='${item.Merchant_Business_Scope_SerialNumber}'`,
                            },
                            success: (res) => {
                                item['Children'].merchant_qualification = res;
                                that.showComponent = false;
                                that.$nextTick(() => (that.showComponent = true))
                            },
                            complete: (XMLHttpRequest) => {
                                requestPretreatment(XMLHttpRequest);
                            },
                        });
                        $.ajax({
                            headers: requestHeaders(),
                            url: `${mh}/generalBusiness/generalQueryByTableNameWithOriginal`,
                            method: "post",
                            data: {
                                Data: 'merchant_business_mapping_blue_plate',
                                Condition: `Merchant_Business_Scope_SerialNumber='${item.Merchant_Business_Scope_SerialNumber}'`,
                            },
                            success: (data) => {
                                let str = data.map(i => "'" + i.Merchant_Mapping_Blue_Plate_SerialNumber + "'").join(",");
                                $.ajax({
                                    headers: requestHeaders(),
                                    url: `${mh}/generalBusiness/generalQueryByTableNameWithOriginal`,
                                    method: "post",
                                    data: {
                                        Data: 'merchant_alias_image',
                                        Condition: `Merchant_Mapping_Blue_Plate_SerialNumber IN (${str ? str : ''})`,
                                    },
                                    success: (data1) => {
                                        data.forEach(item => {
                                            item.Children = {
                                                merchant_alias_image: data1.filter(i => i.Merchant_Mapping_Blue_Plate_SerialNumber == item.Merchant_Mapping_Blue_Plate_SerialNumber)
                                            }
                                        })
                                        this.merchant_business_mapping_blue_plate = [...this.merchant_business_mapping_blue_plate, ...data];
                                        this.dataForm.Blue_Plate_SerialNumber = data[0].Blue_Plate_SerialNumber;
                                        data.forEach(item => {
                                            let obj = res.filter(i => i.Merchant_Business_Scope_SerialNumber == item.Merchant_Business_Scope_SerialNumber)[0];
                                            item.Merchant_Alias_Type_SerialNumber = item.Merchant_Alias_Type_SerialNumber ? item.Merchant_Alias_Type_SerialNumber.split(",") : [];
                                            this.select_blue_plate[obj.Merchant_Category_SerialNumber] = item;
                                            // this.room_type.push({
                                            //     Merchant_SerialNumber: obj.Merchant_SerialNumber,
                                            //     Merchant_Category_SerialNumber: obj.Merchant_Category_SerialNumber,
                                            //     Blue_Plate_SerialNumber:data[0].Blue_Plate_SerialNumber,
                                            //     Row_Status: '0',
                                            // })
                                        });
                                        this.showblueplate = false;
                                        this.$nextTick(() => (that.showblueplate = true))
                                    },
                                    complete: (XMLHttpRequest) => {
                                        requestPretreatment(XMLHttpRequest);
                                    },
                                });
                            },
                            complete: (XMLHttpRequest) => {
                                requestPretreatment(XMLHttpRequest);
                            },
                        });
                    })
                },
                complete: (XMLHttpRequest) => {
                    requestPretreatment(XMLHttpRequest);
                },
            })
        },
        async handleSubmit() {
            const allValid = await this.validateAllForms();
            if (allValid) {
                this.loading = true;
                let ls_URL = window.location.href;
                const action = getQueryObject(ls_URL, "action");   // 获取 action 参数
                let lJSONObject_Data_Options = new Object();
                lJSONObject_Data_Options = JSON.parse(document.getElementById("MainTable").getAttribute("data-options"));

                let ls_MainTableName = lJSONObject_Data_Options.TableName;
                let ls_DataForm = lJSONObject_Data_Options.form;
                //没有子表下面内容就会报错，try/catch抛出异常
                try {
                    //可能涉及多个子表
                    document.getElementById("ChildTable").querySelectorAll(".ChildTable").forEach(item => {
                        let lJSONObject_ChildData_Options = new Object();
                        lJSONObject_ChildData_Options = JSON.parse(item.getAttribute("data-options"));

                        let ls_ChildTableName = lJSONObject_ChildData_Options.TableName;
                        let ls_ChildDataForm = lJSONObject_ChildData_Options.form;
                        // let ls_ParentTableName = lJSONObject_ChildData_Options.ParentTableName;
                        //建立子表结构体
                        let JSONArray_ChildRecord = new Array();
                        JSONArray_ChildRecord = this[ls_ChildDataForm];
                        if (!this[ls_DataForm].Children) {
                            this[ls_DataForm].Children = new Object();
                        }
                        this[ls_DataForm].Children[ls_ChildTableName] = JSONArray_ChildRecord;
                    })
                } catch (error) {

                }
                //建立新增提交结构
                //深拷贝
                let dataForm = deepClone(this[ls_DataForm]);

                let lJSONObject_DataSet = new Object();
                if (action == 'Add') {
                    if (this.nodeKey) {
                        dataForm.Parent_SerialNumber = this.nodeKey;
                    }

                    dataForm.Children.merchant_business_scope.forEach(item => {
                        let obj = {
                            Merchant_Business_Scope_SerialNumber: item.Merchant_Business_Scope_SerialNumber,
                            ...deepClone(this.select_blue_plate[item.Merchant_Category_SerialNumber])
                        }
                        obj.Merchant_Alias_Type_SerialNumber = obj.Merchant_Alias_Type_SerialNumber.length > 0 ? obj.Merchant_Alias_Type_SerialNumber.join(',') : ''
                        item.Children.merchant_business_mapping_blue_plate.push(obj)
                    })
                    let lJSONArray_Record = new Array();
                    lJSONArray_Record.push(dataForm);
                    let lJSONObject_Table = new Object();
                    lJSONObject_Table[ls_MainTableName] = lJSONArray_Record;
                    lJSONObject_DataSet[action] = lJSONObject_Table;
                } else if (action == 'Modify') {
                    let merchant_qualification = [], merchant_business_mapping_blue_plate = [], merchant_alias_image = [];
                    //将孙表提出来
                    dataForm.Children.merchant_business_scope.filter(i => i.Row_Status != '1').forEach(item => {
                        //处理资质

                        //判断经营范围是否为老的，老的有外键，可以提出去提交处理， 新的只能同步提交
                        if (Object.keys(item).some(item => item.includes('_Original'))) {
                            merchant_qualification = [...merchant_qualification, ...item.Children.merchant_qualification];
                            delete item.Children.merchant_qualification;
                        }

                        //处理门店  因为一个范围对应一个门店
                        let obj = this.merchant_business_mapping_blue_plate.filter(i => i.Merchant_Business_Scope_SerialNumber == item.Merchant_Business_Scope_SerialNumber)[0];
                        if (obj) {//存在，原数据库有值，做修改
                            let obj1 = {
                                ...obj,
                                ...this.select_blue_plate[item.Merchant_Category_SerialNumber],
                                Merchant_Business_Scope_SerialNumber: item.Merchant_Business_Scope_SerialNumber,
                            }
                            obj1.Merchant_Alias_Type_SerialNumber = obj1.Merchant_Alias_Type_SerialNumber.length > 0 ? obj1.Merchant_Alias_Type_SerialNumber.join(',') : ''
                            merchant_business_mapping_blue_plate.push(obj1)

                            //将图片提出来，修改的同步提交就行， 添加的只能提出来，当前没有做方法整理
                            obj.Children.merchant_alias_image.forEach(item => {
                                if (!Object.keys(item).some(item => item.includes('_Original'))) {//将添加的提出来单独提交
                                    merchant_alias_image.push(item);
                                }
                            })

                        } else {//不存在原数据库有值，做添加
                            let obj1 = {
                                ...this.select_blue_plate[item.Merchant_Category_SerialNumber],
                                Merchant_Business_Scope_SerialNumber: item.Merchant_Business_Scope_SerialNumber,
                            }
                            obj1.Merchant_Alias_Type_SerialNumber = obj1.Merchant_Alias_Type_SerialNumber.length > 0 ? obj1.Merchant_Alias_Type_SerialNumber.join(',') : ''
                            item.Children.merchant_business_mapping_blue_plate.push(obj1)
                        }
                    })
                    //将删掉的门店做逻辑删除
                    this.merchant_business_mapping_blue_plate.forEach(item => {
                        let obj = merchant_business_mapping_blue_plate.filter(i => i.Merchant_Business_Scope_SerialNumber == item.Merchant_Business_Scope_SerialNumber)[0]
                        if (!obj) {
                            item.Row_Status = '1';
                            merchant_business_mapping_blue_plate.push(item);
                        }
                    })

                    const { add, modify } = this.deal(dataForm);

                    let lJSONArray_Record = new Array();
                    lJSONArray_Record.push(modify);
                    let lJSONObject_Table = new Object();
                    lJSONObject_Table[ls_MainTableName] = lJSONArray_Record;

                    lJSONObject_DataSet[action] = lJSONObject_Table;
                    lJSONObject_DataSet['Add'] = new Object();

                    if (add != null) {
                        let lJSONArray_Record_Add = new Array();
                        lJSONArray_Record_Add.push(add);

                        let lJSONObject_Table_Add = new Object();
                        lJSONObject_Table_Add[ls_MainTableName] = lJSONArray_Record_Add;

                        lJSONObject_DataSet['Add'] = lJSONObject_Table_Add;
                    }

                    lJSONObject_DataSet['Add']['merchant_qualification'] = [];
                    lJSONObject_DataSet[action]['merchant_business_mapping_blue_plate'] = [];
                    lJSONObject_DataSet[action]['merchant_qualification'] = [];

                    for (let i = 0; i < merchant_business_mapping_blue_plate.length; i++) {
                        const obj = merchant_business_mapping_blue_plate[i];
                        if (Object.keys(obj).some(item => item.includes('_Original'))) {
                            lJSONObject_DataSet[action]['merchant_business_mapping_blue_plate'].push(obj)
                        }
                    }

                    for (let i = 0; i < merchant_qualification.length; i++) {
                        const obj = merchant_qualification[i];
                        if (!Object.keys(obj).some(item => item.includes('_Original'))) {
                            lJSONObject_DataSet['Add']['merchant_qualification'].push(obj)
                        } else {
                            lJSONObject_DataSet[action]['merchant_qualification'].push(obj)
                        }
                    }

                    lJSONObject_DataSet['Add']['merchant_alias_image'] = merchant_alias_image;
                }
                let Operation_Main = JSON.stringify(deepClone(lJSONObject_DataSet));
                if (!lJSONObject_DataSet['Add']) {
                    lJSONObject_DataSet['Add'] = new Object();
                }
                lJSONObject_DataSet['Add']['base_operation_log'] = [{
                    Operation_Type: '0',
                    Operation_Path: this.relativePath,
                    Operation_Main,
                    Operation_Interface: "generalSave",
                    Operation_IP: getIpAddress()
                }]

                // console.log(lJSONObject_DataSet);

                submitSave(lJSONObject_DataSet, (res) => {
                    if (res.Status == 'success') {
                        window.location.href = './index.html'
                    }
                    this.loading = false;
                })
            } else {
                this.$message({
                    message: '存在未填写的必填项！',
                    type: 'warning'
                });
            }
        },
    },
};

const { createApp, ref } = Vue;
const app = createApp(App);
app.use(ElementPlus, { locale: zhCn });
//这种方式是引入全部图标，无需单个引入
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
    app.component(key, component);
}
app.component('yl-upload', ylUpload);
app.component('yl-select', ylSelect);
app.component('yl-cascader', ylCascader);
app.component('yl-text-editor', ylTextEditor)
const ElMessage = ElementPlus.ElMessage;
app.mount("#app");
